const numFilter = function(value, num, unit) {
    if (Object.is(value, undefined) || Object.is(value, null) || value === '') {
        return '-';
    } else {
        return Number(value).toFixed(num) + (unit || '');
    }
}
const ifNull = function(value, unit) {
    if (Object.is(value, undefined) || Object.is(value, null) || value === "") {
        return '-';
    } else {
        return value + (unit || '');
    }
}
const units = function(input, unit, tofixed) {
    if (Object.is(input, undefined) || Object.is(input, null) || input === "") {
        return '-';
    } else {
        input = Number(input);
        let inp_abs = Math.abs(input);
        if (unit == 'W' && inp_abs < 1000) {
            input = input.toFixed(tofixed) + 'W';
        } else if (unit == 'kW' && inp_abs < 1000) {
            input = input.toFixed(tofixed) + 'kW';
        } else if (unit == 'MW' && inp_abs < 1000) {
            input = input.toFixed(tofixed) + 'MW';
        } else if (unit == 'kWh' && inp_abs < 1000) {
            input = input.toFixed(tofixed) + 'kWh';
        } else if (unit == 'W' && inp_abs >= 1000) {
            input = (input / 1000).toFixed(tofixed) + 'kW';
        } else if (unit == 'kW' && inp_abs >= 1000) {
            input = (input / 1000).toFixed(tofixed) + 'MW';
        } else if (unit == 'kWh' && inp_abs >= 1000) {
            input = (input / 1000).toFixed(tofixed) + 'MWh';
        }
        return input;
    }
}
const stringLength = function(originVal, num) {
    let str = originVal || ''
    if (!num) {
        num = 10
    }
    if (str.length > num) {
        return str.substr(0, num) + '...'
    } else {
        return str
    }
}
export {
    numFilter,
    units,
    ifNull,
    stringLength
}